package com.yonyou.crm.bpub.template.rmimpl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.yonyou.crm.bpub.template.entity.TemplatesVO;
import com.yonyou.crm.bpub.template.rmitf.ITemplatesRmService;
import com.yonyou.crm.bpub.template.service.TemplatesBizServiceImpl;
import com.yonyou.crm.sys.modules.service.LayoutBizServiceImpl;

public class TemplatesRmServiceImpl implements ITemplatesRmService{
	
	@Autowired
	TemplatesBizServiceImpl bizService;
	@Autowired
	private LayoutBizServiceImpl layoutService;
	
	
	public TemplatesVO getTemplate(Map<String, Object> param){
		TemplatesVO template = new TemplatesVO();
		if(param == null) return null;
		Long biztypeId = null;
		if (param.containsKey("subbnstype")) {
			String subbnsType = String.valueOf(param.get("subbnstype"));
			if((subbnsType != null) && (!subbnsType.equals(""))){
				biztypeId = Long.parseLong(param.get("subbnstype").toString());
			}
		}
		if (param.containsKey("module")) {
			String moduleStr = String.valueOf(param.get("module"));
			try{
				Integer module = Integer.valueOf(moduleStr);
				if (module != 0) {
					template = layoutService.getMobileEditTemplateForCurrentUser(biztypeId);
				} else {
					template = bizService.getTemplate(param);
				}
			} catch(Exception e) {
				template = bizService.getTemplate(param);
			}
		}
		//TemplatesVO template = layoutService.getMobileEditTemplateForCurrentUser(biztypeId);
		return template;
	}
}
